
<template>
	<div class="moneyList">
		<div class="top">
			<div class="time pad">
				<span class="label">营业执照号：</span>
				<el-input v-model="filter.businessLicense" placeholder="请输入内容"></el-input>
			</div>
			<div class="time pad">
				<span class="label">商户账户名称：</span>
				<el-input v-model="filter.merchantName" placeholder="请输入内容"></el-input>
			</div>
			<div class="time pad">
				<span class="label">创建时间：</span>
        <el-date-picker
          v-model="TimeArr"
          type="daterange"
          value-format="yyyy-MM-dd"
          @change="getTimeArr"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
			</div>
			<div class="time pad">
				<span class="label">商户编号：</span>
				<el-input v-model="filter.merchantId" placeholder="请输入内容"></el-input>
			</div>
			<div class="btn pad">
				<el-button @click="setReset">重置</el-button>
				<el-button type="primary" @click="search">查询</el-button>
			</div>
		</div>
		<div class="main">
			<div class="main_top">
				<div class="lef_box">
					<el-button size="small" type="primary" @click="add">新建</el-button>
					<div class="lef">
						<div class="" 
						v-for="item in type" 
						:class="['list',currentNavtab == item.id ? 'active' : '' ]"   
						:key="item.id" 
						:value="item.id" @click="handleTab(item.id)">
						{{item.value}}
						</div>
					</div>
				</div>
				<export-excel-button
          title="资金账户管理表"
          action="/entry/v1/fund/merchantFundAccountExport"
          :params="ExportParams"
        />
			</div>
			<ex-table
				ref="table"
				:loading="loading"
				:table-column="tableColumn"
				:table-data="tableData"
				@pageSizeChange="handleSizeChange"
				@currentPageChange="handleCurrentChange"
			>
				<template v-slot:operate="{ scope }">
					<el-button @click="lookDetail(scope.row)" size="small" type="primary" v-if="scope.row.status == '1'">查看</el-button>
					<el-button @click="lookDetail(scope.row)" size="small" type="primary" v-if="scope.row.status == '2'">修改</el-button>
					<el-button @click="toManagement(scope.row)" size="small" v-if="scope.row.status == '3'">管理</el-button>
					<el-button @click="getDelete(scope.row.id)" size="small" type="danger" v-if="scope.row.status == '2'">删除</el-button>
          <el-button @click="handleMessage(scope.row.merchantId)" size="small" type="primary" v-if="scope.row.type == '3' && scope.row.entryStatus == 'INIT'">重新推送签约短信</el-button>
				</template>
			</ex-table>
		</div>
	</div>
</template>
<script>
// components
// import FilterSearch from './components/newIncreaseVerify/FilterSearch'
// api
import ExportExcelButton from "@/components/ExportExcelButton/index";
import {
  getMoneyList,
  getqueryStpeStatus,
  deleteList,
  ysSendSignSms,
} from '@/api/moneyManagement'

// mixins
import handlePageMixin from '@/mixins/handlePageMixin'


export default {
  name: 'moneyList',
  components: {
    ExportExcelButton,
  },
  mixins: [handlePageMixin],
  data() {
    return {
      loading: false,
			options: [
        { label: '选项1', value: '1' },
        { label: '选项2', value: '2' },
        { label: '选项3', value: '3' },
        { label: '选项4', value: '4' }
      ],
			type:[
				{id: '', value: '全部'},
				{id: '1', value: '等待创建'},
				{id: '2', value: '创建失败'},
				{id: '3', value: '创建成功'},
			],
			tableColumn: [
        { prop: 'id', label: '资金商户编号',width: '200' },
        // { prop: 'typeDict', label: '支付接口公司',width: '150' },
        { prop: 'merchantNo', label: '第三方账户ID' ,width: '130' },
        // { prop: 'merchantId', label: '关联蜜链盟商户号',width: '200' },
        { prop: 'businessLicense', label: '营业执照号',width: '200' },
        { prop: 'merchantName', label: '商户账号名称'},
        // { prop: 'withdrawBalance', label: '可用余额(¥)' ,width: '100'},
        // { prop: 'freezeBalance', label: '冻结余额(¥)' ,width: '100'},
				// { prop: 'fee', label: '提现费率(%)',width: '130' },
        // { prop: 'additionalWorth', label: '综合服务费率' ,width: '130'},
        { prop: 'createTime', label: '创建时间' ,width: '180'},
				{ prop: 'statusDict', label: '状态',width: '100' },
        { label: '操作', slot: true, slotName: 'operate',width: '220',fixed: 'right', }
      ],
      tableData:[],
      TimeArr: [],
      filter:{
        merchantId: '',//商户ID
        businessLicense: '',//营业执照号
        merchantName: '',//商户名称
        createStartTime: '',//创建时间--开始
        createEndTime: '',//创建时间--结束
        status: '',
      },
			value: '',
			time: '',
			currentNavtab: 0,
    }
  },
  computed: {
    ExportParams() {
      const { id: ticketId } = this;
      const params = {
        ...this.pageOptions,
        ...this.filter,
      };
      return params;
    },
  },
  created() {
    this.getList()
	},
  methods: {
    //列表
    getList() {
      this.loading = true
      const params = {
        ...this.pageOptions,
        ...this.filter
      }

      getMoneyList(params).then(res => {
        const { total, records } = res.result
        records.forEach(item => {
          
        })
        
        this.$refs.table.pageOptions.total = total
        this.tableData = records
      }).finally(() => {
        this.loading = false
      })
    },
    //获取时间
    getTimeArr(value){
      console.log("time",value)
      this.filter.createStartTime = this.TimeArr[0]
      this.filter.createEndTime = this.TimeArr[1]
    },
		//切换选项
		handleTab(id){
			console.log("id",id),
			this.currentNavtab = id
      this.filter.status = id
      this.getList()
		},
    //重置
    setReset(){
      this.TimeArr = []
      this.filter.merchantId = ''
      this.filter.businessLicense = ''
      this.filter.merchantName = ''
      this.filter.createStartTime =  ''
      this.filter.createEndTime =  ''
      this.pageOptions.pageNum = 1
      this.$refs.table.pageOptions.pageNum = 1
      this.getList()
    },	
    //搜索
    search(){
      this.pageOptions.pageNum = 1
      this.$refs.table.pageOptions.pageNum = 1
      this.getList()
    },	
    //新建
    add(){
      this.$router.push({
        path: '/moneyManagement/add-money', 
        query:{
          type: 'add'
        }
      })
    },
		//查看
    lookDetail(data){
      var id = data.id
      var orderNo = data.orderNo
      var merchantNo = data.merchantNo
      var status = data.status
      if(status == 1 ||status == 2){
        this.$router.push({
            path: '/moneyManagement/add-money',
            query:{
              fundId: id,
              type: 'edit',
              orderNo: orderNo,
              merchantNo: merchantNo,
            },
           
          })
        
      }else if(status == 3){
        this.$router.push({
          path: '/moneyManagement/money-detail'
        })
      }
    },
    //管理
    toManagement(data){
      var fundId = data.id
      var merchantNo = data.merchantNo
      this.$router.push({
        path: '/moneyManagement/money-detail',
        query:{
              fundId: fundId,
              merchantNo: merchantNo,
            },
      })
    },
    //删除资金账户
    getDelete(id){
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        deleteList(id).then(res => {
          const { } = res.result
          this.getList()
          this.$message({
            message: '删除成功',
            type: type,
            duration: 1500,
          })
          
        }).finally(() => {
          this.loading = false
        })
      }).catch(() => {

			})
      
    },
    //推送短信
    handleMessage(merchantId){
      console.log('merchantId',merchantId)
      var params = {
        merchantId: merchantId
      }
      ysSendSignSms(params).then(res=>{
        if(res.code == 200){ 
          this.$message.success('发送成功')
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
@import './style/moneyList';
.time ::v-deep .el-input{
	width: 200px;
}
.el-select .el-input {
    width: 130px;
}
.first_box{
	::v-deep :nth-child(1).el-input__inner{
		width: 100px;
	}
	::v-deep :nth-child(2).el-input__inner{
		width: 200px;
	}
} 
.input-with-select .el-input-group__prepend {
	background-color: #fff;
}

</style>